package com.bw.aop;

import com.alibaba.fastjson.JSON;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class AroudAop {


    /**
     * 环绕通知
     * @param joinPoint
     * @return
     */
    @Around("execution(* com.bw.service.*.*(..))")
    public Object aop(ProceedingJoinPoint joinPoint) throws Throwable {

        String name = joinPoint.getSignature().getName(); // 获取原方法的方法名
        System.out.println("原方法的名字： " + name) ;
        Object[] args = joinPoint.getArgs(); // 获取原方法的入参
        System.out.println("原方法的入参： " + JSON.toJSONString(args)) ;

        long l = System.currentTimeMillis();
        Object proceed = joinPoint.proceed(); // 执行原方法
        long l2 = System.currentTimeMillis();
        System.out.println("方法的执行耗时是 " + (l2-l));
        System.out.println("原方法的返回值： " + JSON.toJSONString(proceed)) ;
        return proceed;

    }
}
